package org.zoomdev.zoom.dao.test.utils;

import org.zoomdev.zoom.ioc.annotations.Inject;

import javax.sql.DataSource;

public class DaoConnection {
    @Inject(config = "mysql.server")
    private final String server = "mysql8";
    @Inject(config = "mysql.user")
    private final String user = "account";
    @Inject(config = "mysql.pwd")
    private final String password = "123456";
    @Inject(config = "mysql.port")
    private final int port = 3307;
    @Inject(config = "mysql.db")
    private final String db = "cca";


    public DataSource getDataSource() {
        MysqlConnDescription mysqlConnDescription = new MysqlConnDescription();
        mysqlConnDescription.setServer(server);
        mysqlConnDescription.setDbName(db);
        mysqlConnDescription.setUser(user);
        mysqlConnDescription.setPassword(password);
        mysqlConnDescription.setDriverClass("com.mysql.cj.jdbc.Driver");
        mysqlConnDescription.setPort(port);
        DruidDataSourceProvider dataSourceProvider = new DruidDataSourceProvider(mysqlConnDescription);


        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        DataSource dataSource = dataSourceProvider.getDataSource();     //new RawDataSource(dataSourceProvider.getUrl(), user, password);
        return dataSource;
    }
}
